add_executable(python IMPORTED)
find_package (Python COMPONENTS Interpreter REQUIRED)
message("Python interpreter path: " ${Python_EXECUTABLE})
set_property(TARGET python
        PROPERTY IMPORTED_LOCATION ${Python_EXECUTABLE})
set(OBJ_APD_LST
        ${CMAKE_CURRENT_SOURCE_DIR}/ARP
        ${CMAKE_CURRENT_SOURCE_DIR}/DEV
        ${CMAKE_CURRENT_SOURCE_DIR}/PIL
        ${CMAKE_CURRENT_SOURCE_DIR}/ERR
        ${CMAKE_CURRENT_SOURCE_DIR}/ETH
        ${CMAKE_CURRENT_SOURCE_DIR}/IPVX
        ${CMAKE_CURRENT_SOURCE_DIR}/UTIL
        )

#set_source_files_properties(err.c PROPERTIES OBJECT_DEPENDS "${OBJ_APD_LST}")


add_custom_command(
        OUTPUT
            ${CMAKE_CURRENT_SOURCE_DIR}/er.h ${CMAKE_CURRENT_SOURCE_DIR}/ers.h
        COMMAND
            python ${CMAKE_CURRENT_SOURCE_DIR}/errgen.py ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/er.h ${CMAKE_CURRENT_SOURCE_DIR}/ers.h
        DEPENDS errgen.py ${OBJ_APD_LST}
)

list(APPEND INCLUDES_PRIVATE
        "../inc")

option(DEBUG_ERR "Enable err module debug" ON)

if(DEBUG_ERR)
    add_executable(err_t err_test.c err.c ers.h)
    target_compile_definitions(err_t PRIVATE "DEBUG_ERR")
    target_include_directories(err_t
            PRIVATE ${INCLUDES_PRIVATE})
    enable_testing()
    add_test(NAME Err COMMAND err_t
            WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
    set_tests_properties(Err
            PROPERTIES PASS_REGULAR_EXPRESSION "1"
            )
endif()

add_library(err err.c ers.h)

target_include_directories(err
        PRIVATE ${INCLUDES_PRIVATE})
